package com.zhangxin.threadcoreknowledge.stopthread;

import java.util.TreeMap;

public class Demo04CantInterrupt {

    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = () -> {
          int num = 0;
          while (num <= 10000 && !Thread.currentThread().isInterrupted()) {
              if (num % 100 == 0) {
                  System.out.println(num +"是100的倍数");
              }
              num++;
              try {
                  Thread.sleep(10);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          }
        };
        Thread thread = new Thread(runnable);
        thread.start();
        Thread.sleep(5000);
        thread.interrupt();
        /**
         * 效果   虽然中断被拋出来了，但是线程仍然在自己执行
         * 0是100的倍数
         * 100是100的倍数
         * 200是100的倍数
         * 300是100的倍数
         * 400是100的倍数
         * java.lang.InterruptedException: sleep interrupted
         * 	at java.lang.Thread.sleep(Native Method)
         * 	at com.zhangxin.threadcoreknowledge.stopthread.Demo04CantInterrupt.lambda$main$0(Demo04CantInterrupt.java:16)
         * 	at com.zhangxin.threadcoreknowledge.stopthread.Demo04CantInterrupt$$Lambda$1/1555009629.run(Unknown Source)
         * 	at java.lang.Thread.run(Thread.java:745)
         * 500是100的倍数
         * 600是100的倍数
         * 700是100的倍数
         * 800是100的倍数
         * 900是100的倍数
         * 1000是100的倍数
         * .............(后面在继续执行)
         */
    }

}
